package com.inei.cie.dao;

import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.inei.cie.entidades.P5_N;
import com.inei.cie.entidades.P6_1;
import com.inei.cie.entidades.P6_1_10N;
import com.inei.cie.entidades.P6_1_8N;
import com.inei.cie.entidades.P6_2;
import com.inei.cie.entidades.P6_2_4N;
import com.inei.cie.entidades.P7;

public class CapituloVIDao {

	private UtilDB util;
	SQLiteDatabase db;
	Cursor cursor = null;

	public CapituloVIDao(Context context) {
		util = new UtilDB(context);
	}

	// Lista Edificaciones
	public int totalEdificaciones(String id_local, int Nro_Pred) {
		int nroEdificaciones = 0;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P5 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				nroEdificaciones = cursor.getInt(cursor
						.getColumnIndex("P5_Tot_E"));
				cursor.moveToNext();
			}
			Cerrar();
			return nroEdificaciones;
		} else {
			Cerrar();
			return nroEdificaciones;
		}
	}

	public void crearP6_1EdificacionesLocal(String id_local, int nro,
			int Nro_Pred) {
		for (int i = 0; i < nro; i++) {
			if (!existeP6_1Local(id_local, Nro_Pred, i + 1)) {
				db = util.getWritableDatabase();
				ContentValues c = new ContentValues();
				c.put("id_local", id_local);
				c.put("Nro_Ed", (i + 1));
				c.put("Nro_Pred", Nro_Pred);
				db.insert("P6_1", null, c);
				db.close();
				for (int j = 0; j < 10; j++) {
					db = util.getWritableDatabase();
					ContentValues c2 = new ContentValues();
					c2.put("id_local", id_local);
					c2.put("Nro_Ed", (i + 1));
					c2.put("Nro_Pred", Nro_Pred);
					c2.put("P6_1_8ID", (j + 1));
					c2.put("P6_1_8_ACCESIBILIDAD", 0);
					db.insert("P6_1_8N", null, c2);
					db.close();
				}
				for (int j = 0; j < 14; j++) {
					db = util.getWritableDatabase();
					ContentValues c3 = new ContentValues();
					c3.put("id_local", id_local);
					c3.put("Nro_Ed", (i + 1));
					c3.put("Nro_Pred", Nro_Pred);
					c3.put("P6_1_10", (j + 1));
					db.insert("P6_1_10N", null, c3);
					db.close();
				}
			}
		}
	}

	public boolean existeP6_1Local(String id_local, int Nro_Pred, int Nro_Ed) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_1 where id_local=? and Nro_Pred=? and Nro_Ed=?",
						new String[] { id_local + "", Nro_Pred + "",
								Nro_Ed + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	// Menu
	public P6_1 obtenerP6_1Edificacion(String id_local, int Nro_Ed, int Nro_Pred) {
		P6_1 obj = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"SELECT * FROM P6_1 WHERE id_local=? AND Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				obj = new P6_1();
				obj.setId_local(id_local);
				obj.setNro_Ed(Nro_Ed);
				obj.setNro_Pred(Nro_Pred);
				obj.setP6_1_3_Tip(cursor.getInt(cursor
						.getColumnIndex("P6_1_3_Tip")));
				obj.setP6_1_3(cursor.getFloat(cursor.getColumnIndex("P6_1_3")));
				obj.setP6_1_4(cursor.getInt(cursor.getColumnIndex("P6_1_4")));
				obj.setP6_1_5(cursor.getInt(cursor.getColumnIndex("P6_1_5")));
				obj.setP6_1_6(cursor.getInt(cursor.getColumnIndex("P6_1_6")));
				obj.setP6_1_7(cursor.getInt(cursor.getColumnIndex("P6_1_7")));
				obj.setP6_1_8(cursor.getInt(cursor.getColumnIndex("P6_1_8")));
				obj.setP6_1_9(cursor.getInt(cursor.getColumnIndex("P6_1_9")));
				obj.setP6_3_1(cursor.getInt(cursor.getColumnIndex("P6_3_1")));
				obj.setP6_3_1A(cursor.getInt(cursor.getColumnIndex("P6_3_1A")));
				obj.setP6_3_2(cursor.getInt(cursor.getColumnIndex("P6_3_2")));
				obj.setP6_3_2A(cursor.getInt(cursor.getColumnIndex("P6_3_2A")));
				obj.setP6_3_2B(cursor.getInt(cursor.getColumnIndex("P6_3_2B")));
				obj.setP6_3_2C(cursor.getInt(cursor.getColumnIndex("P6_3_2C")));
				obj.setP6_3_2D(cursor.getInt(cursor.getColumnIndex("P6_3_2D")));
				obj.setP6_3_3(cursor.getInt(cursor.getColumnIndex("P6_3_3")));
				obj.setP6_3_3A(cursor.getInt(cursor.getColumnIndex("P6_3_3A")));
				obj.setP6_4_1(cursor.getInt(cursor.getColumnIndex("P6_4_1")));
				obj.setP6_4_1A(cursor.getInt(cursor.getColumnIndex("P6_4_1A")));
				obj.setP6_4_2(cursor.getInt(cursor.getColumnIndex("P6_4_2")));
				obj.setP6_5_1(cursor.getInt(cursor.getColumnIndex("P6_5_1")));
				obj.setP6_5_1A(cursor.getInt(cursor.getColumnIndex("P6_5_1A")));
				obj.setP6_5_2(cursor.getInt(cursor.getColumnIndex("P6_5_2")));
				obj.setP6_OBS(cursor.getString(cursor.getColumnIndex("P6_OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				cursor.moveToNext();
			}
		}
		Cerrar();
		return obj;
	}

	// Seccion A
	public List<Object> obtenerEdificacionA(String id_local, int Nro_Ed,
			int Nro_Pred) {
		P6_1 obj = new P6_1();
		List<P6_1_8N> lObj8 = new ArrayList<P6_1_8N>();
		List<P6_1_10N> lObj10 = new ArrayList<P6_1_10N>();
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_1 where id_local=? and Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			obj.setId_local(cursor.getString(cursor.getColumnIndex("id_local")));
			obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
			obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
			obj.setP6_1_3_Tip(cursor.getInt(cursor.getColumnIndex("P6_1_3_Tip")));
			obj.setP6_1_3(cursor.getFloat(cursor.getColumnIndex("P6_1_3")));
			obj.setP6_1_4(cursor.getInt(cursor.getColumnIndex("P6_1_4")));
			obj.setP6_1_5(cursor.getInt(cursor.getColumnIndex("P6_1_5")));
			obj.setP6_1_6(cursor.getInt(cursor.getColumnIndex("P6_1_6")));
			obj.setP6_1_7(cursor.getInt(cursor.getColumnIndex("P6_1_7")));
			obj.setP6_1_8(cursor.getInt(cursor.getColumnIndex("P6_1_8")));
			obj.setP6_1_9(cursor.getInt(cursor.getColumnIndex("P6_1_9")));
			obj.setP6_3_1(cursor.getInt(cursor.getColumnIndex("P6_3_1")));
			obj.setP6_3_1A(cursor.getInt(cursor.getColumnIndex("P6_3_1A")));
			obj.setP6_3_2(cursor.getInt(cursor.getColumnIndex("P6_3_2")));
			obj.setP6_3_2A(cursor.getInt(cursor.getColumnIndex("P6_3_2A")));
			obj.setP6_3_2B(cursor.getInt(cursor.getColumnIndex("P6_3_2B")));
			obj.setP6_3_2C(cursor.getInt(cursor.getColumnIndex("P6_3_2C")));
			obj.setP6_3_2D(cursor.getInt(cursor.getColumnIndex("P6_3_2D")));
			obj.setP6_3_3(cursor.getInt(cursor.getColumnIndex("P6_3_3")));
			obj.setP6_3_3A(cursor.getInt(cursor.getColumnIndex("P6_3_3A")));
			obj.setP6_4_1(cursor.getInt(cursor.getColumnIndex("P6_4_1")));
			obj.setP6_4_1A(cursor.getInt(cursor.getColumnIndex("P6_4_1A")));
			obj.setP6_4_2(cursor.getInt(cursor.getColumnIndex("P6_4_2")));
			obj.setP6_5_1(cursor.getInt(cursor.getColumnIndex("P6_5_1")));
			obj.setP6_5_1A(cursor.getInt(cursor.getColumnIndex("P6_5_1A")));
			obj.setP6_5_2(cursor.getInt(cursor.getColumnIndex("P6_5_2")));
			obj.setP6_OBS(cursor.getString(cursor.getColumnIndex("P6_OBS")));
			boolean estado = cursor.getInt(cursor.getColumnIndex("SwCompleto")) == 1 ? true
					: false;
			obj.setSwCompleto(estado);
			boolean enviado = cursor.getInt(cursor.getColumnIndex("SwEnviado")) == 1 ? true
					: false;
			obj.setSwEnviado(enviado);
			obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
		}
		cursor = null;
		cursor = db
				.rawQuery(
						"select * from P6_1_8N where id_local=? and Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				P6_1_8N obj8 = new P6_1_8N();
				obj8.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj8.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj8.setNro_Pred(cursor.getInt(cursor
						.getColumnIndex("Nro_Pred")));
				obj8.setP6_1_8ID(cursor.getInt(cursor
						.getColumnIndex("P6_1_8ID")));
				obj8.setP6_1_8_ACCESIBILIDAD(cursor.getInt(cursor
						.getColumnIndex("P6_1_8_ACCESIBILIDAD")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj8.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj8.setSwEnviado(enviado);
				obj8.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lObj8.add(obj8);
				cursor.moveToNext();
			}
		}
		cursor = null;
		cursor = db
				.rawQuery(
						"select * from P6_1_10N where id_local=? and Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				P6_1_10N obj10 = new P6_1_10N();
				obj10.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj10.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj10.setNro_Pred(cursor.getInt(cursor
						.getColumnIndex("Nro_Pred")));
				obj10.setP6_1_10(cursor.getInt(cursor.getColumnIndex("P6_1_10")));
				obj10.setP6_1_10_e(cursor.getInt(cursor
						.getColumnIndex("P6_1_10_e")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj10.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj10.setSwEnviado(enviado);
				obj10.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lObj10.add(obj10);
				cursor.moveToNext();
			}
		}
		List<Object> lista = new ArrayList<Object>();
		lista.add(obj);
		lista.add(lObj8);
		lista.add(lObj10);
		Cerrar();
		return lista;
	}

	public long actualizarEdificacionA(P6_1 obj, List<P6_1_8N> lObj8,
			List<P6_1_10N> lObj10) {
		db = util.getWritableDatabase();
		ContentValues valores = new ContentValues();
		valores.put("P6_1_3_Tip", obj.getP6_1_3_Tip());
		valores.put("P6_1_3", obj.getP6_1_3());
		valores.put("P6_1_4", obj.getP6_1_4());
		valores.put("P6_1_5", obj.getP6_1_5());
		valores.put("P6_1_6", obj.getP6_1_6());
		valores.put("P6_1_7", (obj.getP6_1_6() == 1 ? obj.getP6_1_7() : null));
		valores.put("P6_1_8", obj.getP6_1_8());
		valores.put("P6_1_9", obj.getP6_1_9());
		valores.put("P6_3_1", obj.getP6_3_1());
		valores.put("P6_3_1A", obj.getP6_3_1A());
		valores.put("P6_3_2", obj.getP6_3_2());
		valores.put("P6_3_2A", obj.getP6_3_2A());
		valores.put("P6_3_2B", obj.getP6_3_2B());
		valores.put("P6_3_2C", obj.getP6_3_2C());
		valores.put("P6_3_2D", obj.getP6_3_2D());
		valores.put("P6_3_3", obj.getP6_3_3());
		valores.put("P6_3_3A", obj.getP6_3_3A());
		valores.put("P6_4_1", obj.getP6_4_1());
		valores.put("P6_4_1A", obj.getP6_4_1A());
		valores.put("P6_4_2", obj.getP6_4_2());
		valores.put("P6_5_1", obj.getP6_5_1());
		valores.put("P6_5_1A", obj.getP6_5_1A());
		valores.put("P6_5_2", obj.getP6_5_2());
		valores.put("P6_OBS", obj.getP6_OBS());
		valores.put("Version", obj.getVersion());
		valores.put("SwCompleto", obj.isSwCompleto());
		valores.put("SwEnviado", obj.isSwEnviado());
		long id = db.update("P6_1", valores,
				"id_local=? and Nro_Ed=? and Nro_Pred=?",
				new String[] { obj.getId_local() + "", obj.getNro_Ed() + "",
						obj.getNro_Pred() + "" });

		for (int i = 0; i < lObj8.size(); i++) {
			ContentValues valores8 = new ContentValues();
			valores8.put("P6_1_8_ACCESIBILIDAD", lObj8.get(i)
					.getP6_1_8_ACCESIBILIDAD());
			valores8.put("Version", lObj8.get(i).getVersion());
			valores8.put("SwCompleto", lObj8.get(i).isSwCompleto());
			valores8.put("SwEnviado", lObj8.get(i).isSwEnviado());
			id = db.update("P6_1_8N", valores8,
					"id_local=? and Nro_Ed=? and P6_1_8ID=? and Nro_Pred=?",
					new String[] { lObj8.get(i).getId_local() + "",
							lObj8.get(i).getNro_Ed() + "",
							lObj8.get(i).getP6_1_8ID() + "",
							lObj8.get(i).getNro_Pred() + "" });
		}
		for (int i = 0; i < lObj10.size(); i++) {
			ContentValues valores10 = new ContentValues();
			valores10.put(" P6_1_10_e", lObj10.get(i).getP6_1_10_e());
			valores10.put("Version", lObj10.get(i).getVersion());
			valores10.put("SwCompleto", lObj10.get(i).isSwCompleto());
			valores10.put("SwEnviado", lObj10.get(i).isSwEnviado());
			id = db.update("P6_1_10N", valores10,
					"id_local=? and Nro_Ed=? and P6_1_10=? and Nro_Pred=?",
					new String[] { lObj10.get(i).getId_local() + "",
							lObj10.get(i).getNro_Ed() + "",
							lObj10.get(i).getP6_1_10() + "",
							lObj10.get(i).getNro_Pred() + "" });
		}
		Cerrar();
		return id;
	}

	// Seccion B

	public List<P6_2> obtenerListadoAmbientes(String id_local, int Nro_Ed,
			int Nro_Pred) {
		List<P6_2> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2 where id_local=? and Nro_Ed=? and Nro_Pred=? order by P6_2_2 asc",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2>();
			while (!cursor.isAfterLast()) {
				P6_2 obj = new P6_2();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_2_4N> obtenerListadoModalidades(String id_local, int Nro_Ed,
			int Nro_Pred) {
		List<P6_2_4N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2_4N where id_local=? and Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2_4N>();
			while (!cursor.isAfterLast()) {
				P6_2_4N obj2_4 = new P6_2_4N();
				obj2_4.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj2_4.setNro_Pred(cursor.getInt(cursor
						.getColumnIndex("Nro_Pred")));
				obj2_4.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj2_4.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj2_4.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj2_4.setP6_2_4ID(cursor.getInt(cursor
						.getColumnIndex("P6_2_4ID")));
				obj2_4.setP6_2_4MOD(cursor.getInt(cursor
						.getColumnIndex("P6_2_4MOD")));
				obj2_4.setP6_2_4TURNO_M(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_M")));
				obj2_4.setP6_2_4TURNO_T(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_T")));
				obj2_4.setP6_2_4TURNO_N(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_N")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj2_4.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj2_4.setSwEnviado(enviado);
				obj2_4.setVersion(cursor.getInt(cursor
						.getColumnIndex("Version")));
				lista.add(obj2_4);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public void crearAmbientes(String id_local, int Nro_Pred, int Nro_Ed) {
		if (!existenAmbientes(id_local, Nro_Pred, Nro_Ed)) {
			List<P5_N> lista = null;
			db = util.getReadableDatabase();
			cursor = db
					.rawQuery(
							"select * from P5_N where id_local=? and Nro_Pred=? and P5_Ed_Nro=?",
							new String[] { id_local + "", Nro_Pred + "",
									Nro_Ed + "" });
			if (cursor.moveToFirst()) {
				lista = new ArrayList<P5_N>();
				while (!cursor.isAfterLast()) {
					P5_N obj = new P5_N();
					obj.setP5_NroPiso(cursor.getInt(cursor
							.getColumnIndex("P5_NroPiso")));
					obj.setP5_TotAmb(cursor.getInt(cursor
							.getColumnIndex("P5_TotAmb")));
					lista.add(obj);
					cursor.moveToNext();
				}
			}
			Cerrar();

			if (lista != null) {
				for (P5_N p5_N : lista) {
					for (int i = 0; i < p5_N.getP5_TotAmb(); i++) {
						db = util.getWritableDatabase();
						ContentValues c = new ContentValues();
						c.put("id_local", id_local);
						c.put("Nro_Pred", Nro_Pred);
						c.put("Nro_Ed", Nro_Ed);
						c.put("P6_2_1", (i + 1));
						c.put("P6_2_2", p5_N.getP5_NroPiso());
						db.insert("P6_2", null, c);
						db.close();
					}
				}
			}
		}
	}

	public void eliminarEdificacion(String id_local, int Nro_Pred,
			int edificacion) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete("P5_N", "id_local=? and Nro_Pred=? and P5_Ed_Nro=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P5_N> listaP5 = obtenerEdificacionesP5_N(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P7", "id_local=? and Nro_Pred=? and Nro_Ed=?", new String[] {
				id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P7> listaP7 = obtenerEdificacionesP7(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_1", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_1> listaP6_1 = obtenerEdificacionesP6_1(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_1_8N", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_1_8N> listaP6_1_8 = obtenerEdificacionesP6_1_8N(id_local,
				Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_1_10N", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_1_10N> listaP6_1_10 = obtenerEdificacionesP6_1_10N(id_local,
				Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_2", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_2> listaP6_2 = obtenerEdificacionesP6_2(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_2_4N", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_2_4N> listaP6_2_4 = obtenerEdificacionesP6_2_4N(id_local,
				Nro_Pred);

		if (listaP5 != null) {
			// P5_N
			for (int i = edificacion; i <= listaP5.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues c = new ContentValues();
				c.put("P5_Ed_Nro", i);
				db.update("P5_N", c,
						"id_local=? and Nro_Pred=? and P5_Ed_Nro=?",
						new String[] { id_local + "", Nro_Pred + "",
								(i + 1) + "" });
				db.close();
			}
		}

		if (listaP7 != null) {
			// P7
			for (int i = edificacion; i <= listaP7.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues c = new ContentValues();
				c.put("Nro_Ed", i);
				db.update("P7", c, "id_local=? and Nro_Pred=? and Nro_Ed=?",
						new String[] { id_local + "", Nro_Pred + "",
								(i + 1) + "" });
				db.close();
			}
		}
		if (listaP6_1 != null) {
			// P6_1
			if (listaP6_1 != null) {
				for (int i = edificacion; i <= listaP6_1.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_1", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_1_8N
			if (listaP6_1_8 != null) {
				for (int i = edificacion; i <= listaP6_1_8.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_1_8N", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_1_10N
			if (listaP6_1_10 != null) {
				for (int i = edificacion; i <= listaP6_1_10.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_1_10N", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_2
			if (listaP6_2 != null) {
				for (int i = edificacion; i <= listaP6_2.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_2", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_2_4N
			if (listaP6_2_4 != null) {
				for (int i = edificacion; i <= listaP6_2_4.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_2_4N", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
		}

		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		db = util.getWritableDatabase();
		ContentValues c = new ContentValues();
		c.put("P5_Tot_E", total);
		db.update("P5", c, "id_local=? and Nro_Pred=?", new String[] {
				id_local + "", Nro_Pred + "" });
		Cerrar();
	}

	public List<P5_N> obtenerEdificacionesP5_N(String id_local, int Nro_Pred) {
		List<P5_N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P5_N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P5_N>();
			while (!cursor.isAfterLast()) {
				P5_N obj = new P5_N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setP5_NroPiso(cursor.getInt(cursor
						.getColumnIndex("P5_NroPiso")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP5_Ed_Nro(cursor.getInt(cursor
						.getColumnIndex("P5_Ed_Nro")));
				obj.setP5_TotAmb(cursor.getInt(cursor
						.getColumnIndex("P5_TotAmb")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P7> obtenerEdificacionesP7(String id_local, int Nro_Pred) {
		List<P7> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P7 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P7>();
			while (!cursor.isAfterLast()) {
				P7 obj = new P7();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP7_1_2(cursor.getInt(cursor.getColumnIndex("P7_1_2")));
				obj.setP7_1_3(cursor.getInt(cursor.getColumnIndex("P7_1_3")));
				obj.setP7_1_4(cursor.getInt(cursor.getColumnIndex("P7_1_4")));
				obj.setP7_1_5(cursor.getInt(cursor.getColumnIndex("P7_1_5")));
				obj.setP7_1_6(cursor.getInt(cursor.getColumnIndex("P7_1_6")));
				obj.setP7_1_7(cursor.getInt(cursor.getColumnIndex("P7_1_7")));
				obj.setP7_1_8(cursor.getInt(cursor.getColumnIndex("P7_1_8")));
				obj.setP7_1_9(cursor.getInt(cursor.getColumnIndex("P7_1_9")));
				obj.setP7_1_9A(cursor.getInt(cursor.getColumnIndex("P7_1_9A")));
				obj.setP7_1_9B(cursor.getInt(cursor.getColumnIndex("P7_1_9B")));
				obj.setP7_1_9C(cursor.getInt(cursor.getColumnIndex("P7_1_9C")));
				obj.setP7_1_9D(cursor.getInt(cursor.getColumnIndex("P7_1_9D")));
				obj.setP7_1_10(cursor.getInt(cursor.getColumnIndex("P7_1_10")));
				obj.setP7_1_11(cursor.getInt(cursor.getColumnIndex("P7_1_11")));
				obj.setP7_1_12(cursor.getInt(cursor.getColumnIndex("P7_1_12")));
				obj.setP7_1_13(cursor.getInt(cursor.getColumnIndex("P7_1_13")));
				obj.setP7_1_14(cursor.getInt(cursor.getColumnIndex("P7_1_14")));
				obj.setP7_1_15(cursor.getInt(cursor.getColumnIndex("P7_1_15")));
				obj.setP7_1_15A(cursor.getInt(cursor.getColumnIndex("P7_1_15A")));
				obj.setP7_1_15B(cursor.getInt(cursor.getColumnIndex("P7_1_15B")));
				obj.setP7_1_15C(cursor.getInt(cursor.getColumnIndex("P7_1_15C")));
				obj.setP7_1_15D(cursor.getInt(cursor.getColumnIndex("P7_1_15D")));
				obj.setP7_1_16(cursor.getInt(cursor.getColumnIndex("P7_1_16")));
				obj.setP7_1_17(cursor.getInt(cursor.getColumnIndex("P7_1_17")));
				obj.setP7_1_18(cursor.getInt(cursor.getColumnIndex("P7_1_18")));
				obj.setP7_1_19(cursor.getInt(cursor.getColumnIndex("P7_1_19")));
				obj.setP7_1_20(cursor.getInt(cursor.getColumnIndex("P7_1_20")));
				obj.setP7_1_21(cursor.getInt(cursor.getColumnIndex("P7_1_21")));
				obj.setP7_1_22(cursor.getInt(cursor.getColumnIndex("P7_1_22")));
				obj.setP7_1_23(cursor.getInt(cursor.getColumnIndex("P7_1_23")));
				obj.setP7_1_24(cursor.getInt(cursor.getColumnIndex("P7_1_24")));
				obj.setP7_1_25(cursor.getInt(cursor.getColumnIndex("P7_1_25")));
				obj.setP7_1_26(cursor.getInt(cursor.getColumnIndex("P7_1_26")));
				obj.setP7_1_27(cursor.getInt(cursor.getColumnIndex("P7_1_27")));
				obj.setP7_1_28(cursor.getInt(cursor.getColumnIndex("P7_1_28")));
				obj.setP7_2_1(cursor.getInt(cursor.getColumnIndex("P7_2_1")));
				obj.setP7_2_2(cursor.getString(cursor.getColumnIndex("P7_2_2")));
				obj.setP7_OBS(cursor.getString(cursor.getColumnIndex("P7_OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_1> obtenerEdificacionesP6_1(String id_local, int Nro_Pred) {
		List<P6_1> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_1>();
			while (!cursor.isAfterLast()) {
				P6_1 obj = new P6_1();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_1_3(cursor.getFloat(cursor.getColumnIndex("P6_1_3")));
				obj.setP6_1_4(cursor.getInt(cursor.getColumnIndex("P6_1_4")));
				obj.setP6_1_5(cursor.getInt(cursor.getColumnIndex("P6_1_5")));
				obj.setP6_1_6(cursor.getInt(cursor.getColumnIndex("P6_1_6")));
				obj.setP6_1_7(cursor.getInt(cursor.getColumnIndex("P6_1_7")));
				obj.setP6_1_8(cursor.getInt(cursor.getColumnIndex("P6_1_8")));
				obj.setP6_1_9(cursor.getInt(cursor.getColumnIndex("P6_1_9")));
				obj.setP6_3_1(cursor.getInt(cursor.getColumnIndex("P6_3_1")));
				obj.setP6_3_1A(cursor.getInt(cursor.getColumnIndex("P6_3_1A")));
				obj.setP6_3_2(cursor.getInt(cursor.getColumnIndex("P6_3_2")));
				obj.setP6_3_2A(cursor.getInt(cursor.getColumnIndex("P6_3_2A")));
				obj.setP6_3_2B(cursor.getInt(cursor.getColumnIndex("P6_3_2B")));
				obj.setP6_3_2C(cursor.getInt(cursor.getColumnIndex("P6_3_2C")));
				obj.setP6_3_2D(cursor.getInt(cursor.getColumnIndex("P6_3_2D")));
				obj.setP6_3_3(cursor.getInt(cursor.getColumnIndex("P6_3_3")));
				obj.setP6_3_3A(cursor.getInt(cursor.getColumnIndex("P6_3_3A")));
				obj.setP6_4_1(cursor.getInt(cursor.getColumnIndex("P6_4_1")));
				obj.setP6_4_1A(cursor.getInt(cursor.getColumnIndex("P6_4_1A")));
				obj.setP6_4_2(cursor.getInt(cursor.getColumnIndex("P6_4_2")));
				obj.setP6_5_1(cursor.getInt(cursor.getColumnIndex("P6_5_1")));
				obj.setP6_5_1A(cursor.getInt(cursor.getColumnIndex("P6_5_1A")));
				obj.setP6_5_2(cursor.getInt(cursor.getColumnIndex("P6_5_2")));
				obj.setP6_OBS(cursor.getString(cursor.getColumnIndex("P6_OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_1_8N> obtenerEdificacionesP6_1_8N(String id_local,
			int Nro_Pred) {
		List<P6_1_8N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1_8N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_1_8N>();
			while (!cursor.isAfterLast()) {
				P6_1_8N obj = new P6_1_8N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP6_1_8ID(cursor.getInt(cursor.getColumnIndex("P6_1_8ID")));
				obj.setP6_1_8_ACCESIBILIDAD(cursor.getInt(cursor
						.getColumnIndex("P6_1_8_ACCESIBILIDAD")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_1_10N> obtenerEdificacionesP6_1_10N(String id_local,
			int Nro_Pred) {
		List<P6_1_10N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1_10N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_1_10N>();
			while (!cursor.isAfterLast()) {
				P6_1_10N obj = new P6_1_10N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP6_1_10(cursor.getInt(cursor.getColumnIndex("P6_1_10")));
				obj.setP6_1_10_e(cursor.getInt(cursor
						.getColumnIndex("P6_1_10_e")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_2> obtenerEdificacionesP6_2(String id_local, int Nro_Pred) {
		List<P6_2> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_2 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2>();
			while (!cursor.isAfterLast()) {
				P6_2 obj = new P6_2();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj.setP6_2_3(cursor.getInt(cursor.getColumnIndex("P6_2_3")));
				obj.setP6_2_5(cursor.getInt(cursor.getColumnIndex("P6_2_5")));
				obj.setP6_2_6(cursor.getInt(cursor.getColumnIndex("P6_2_6")));
				obj.setP6_2_7(cursor.getInt(cursor.getColumnIndex("P6_2_7")));
				obj.setP6_2_7_O(cursor.getString(cursor
						.getColumnIndex("P6_2_7_O")));
				obj.setP6_2_8(cursor.getInt(cursor.getColumnIndex("P6_2_8")));
				obj.setP6_2_8_O(cursor.getString(cursor
						.getColumnIndex("P6_2_8_O")));
				obj.setP6_2_9(cursor.getInt(cursor.getColumnIndex("P6_2_9")));
				obj.setP6_2_9_O(cursor.getString(cursor
						.getColumnIndex("P6_2_9_O")));
				obj.setP6_2_10(cursor.getInt(cursor.getColumnIndex("P6_2_10")));
				obj.setP6_2_10_O(cursor.getString(cursor
						.getColumnIndex("P6_2_10_O")));
				obj.setP6_2_11(cursor.getInt(cursor.getColumnIndex("P6_2_11")));
				obj.setP6_2_11_O(cursor.getString(cursor
						.getColumnIndex("P6_2_11_O")));
				obj.setP6_2_12(cursor.getInt(cursor.getColumnIndex("P6_2_12")));
				obj.setP6_2_12_O(cursor.getString(cursor
						.getColumnIndex("P6_2_12_O")));
				obj.setP6_2_13(cursor.getInt(cursor.getColumnIndex("P6_2_13")));
				obj.setP6_2_13_O(cursor.getString(cursor
						.getColumnIndex("P6_2_13_O")));
				obj.setP6_2_14_1(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_1")));
				obj.setP6_2_14_2(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_2")));
				obj.setP6_2_14_3(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_3")));
				obj.setP6_2_14_4(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_4")));
				obj.setP6_2_14_5(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_5")));
				obj.setP6_2_14_6(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_6")));
				obj.setP6_2_14a(cursor.getInt(cursor.getColumnIndex("P6_2_14a")));
				obj.setP6_2_14b_1(cursor.getInt(cursor
						.getColumnIndex("P6_2_14b_1")));
				obj.setP6_2_14b_2(cursor.getInt(cursor
						.getColumnIndex("P6_2_14b_2")));
				obj.setP6_2_15(cursor.getInt(cursor.getColumnIndex("P6_2_15")));
				obj.setP6_2_15_O(cursor.getString(cursor
						.getColumnIndex("P6_2_15_O")));
				obj.setP6_2_15a(cursor.getInt(cursor.getColumnIndex("P6_2_15a")));
				obj.setP6_2_16a(cursor.getInt(cursor.getColumnIndex("P6_2_16a")));
				obj.setP6_2_16a_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_b")));
				obj.setP6_2_16a_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_r")));
				obj.setP6_2_16a_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_m")));
				obj.setP6_2_16b(cursor.getInt(cursor.getColumnIndex("P6_2_16b")));
				obj.setP6_2_16b_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_b")));
				obj.setP6_2_16b_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_r")));
				obj.setP6_2_16b_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_m")));
				obj.setP6_2_16c(cursor.getInt(cursor.getColumnIndex("P6_2_16c")));
				obj.setP6_2_16c_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_b")));
				obj.setP6_2_16c_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_r")));
				obj.setP6_2_16c_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_m")));
				obj.setP6_2_16d(cursor.getInt(cursor.getColumnIndex("P6_2_16d")));
				obj.setP6_2_16d_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_b")));
				obj.setP6_2_16d_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_r")));
				obj.setP6_2_16d_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_m")));
				obj.setP6_2_16e(cursor.getInt(cursor.getColumnIndex("P6_2_16e")));
				obj.setP6_2_16e_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_b")));
				obj.setP6_2_16e_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_r")));
				obj.setP6_2_16e_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_m")));
				obj.setP6_2_16e_O(cursor.getString(cursor
						.getColumnIndex("P6_2_16e_O")));
				obj.setP6_2_16f(cursor.getInt(cursor.getColumnIndex("P6_2_16f")));
				obj.setP6_2_17a(cursor.getInt(cursor.getColumnIndex("P6_2_17a")));
				obj.setP6_2_17b(cursor.getInt(cursor.getColumnIndex("P6_2_17b")));
				obj.setP6_2_17c(cursor.getInt(cursor.getColumnIndex("P6_2_17c")));
				obj.setP6_2_17d(cursor.getInt(cursor.getColumnIndex("P6_2_17d")));
				obj.setP6_2_18a(cursor.getInt(cursor.getColumnIndex("P6_2_18a")));
				obj.setP6_2_18a_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_b")));
				obj.setP6_2_18a_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_r")));
				obj.setP6_2_18a_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_m")));
				obj.setP6_2_18b(cursor.getInt(cursor.getColumnIndex("P6_2_18b")));
				obj.setP6_2_18b_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_b")));
				obj.setP6_2_18b_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_r")));
				obj.setP6_2_18b_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_m")));
				obj.setP6_2_18c(cursor.getInt(cursor.getColumnIndex("P6_2_18c")));
				obj.setP6_2_18c_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_b")));
				obj.setP6_2_18c_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_r")));
				obj.setP6_2_18c_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_m")));
				obj.setP6_2_18d(cursor.getInt(cursor.getColumnIndex("P6_2_18d")));
				obj.setP6_2_18d_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_b")));
				obj.setP6_2_18d_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_r")));
				obj.setP6_2_18d_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_m")));
				obj.setP6_2_18e(cursor.getInt(cursor.getColumnIndex("P6_2_18e")));
				obj.setP6_2_18e_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_b")));
				obj.setP6_2_18e_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_r")));
				obj.setP6_2_18e_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_m")));
				obj.setP6_2_18e_O(cursor.getString(cursor
						.getColumnIndex("P6_2_18e_O")));
				obj.setP6_2_18f(cursor.getInt(cursor.getColumnIndex("P6_2_18f")));
				obj.setP6_2_19a(cursor.getInt(cursor.getColumnIndex("P6_2_19a")));
				obj.setP6_2_19b(cursor.getInt(cursor.getColumnIndex("P6_2_19b")));
				obj.setP6_2_19c(cursor.getInt(cursor.getColumnIndex("P6_2_19c")));
				obj.setP6_2_20OBS(cursor.getString(cursor
						.getColumnIndex("P6_2_20OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_2_4N> obtenerEdificacionesP6_2_4N(String id_local,
			int Nro_Pred) {
		List<P6_2_4N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_2_4N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2_4N>();
			while (!cursor.isAfterLast()) {
				P6_2_4N obj = new P6_2_4N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj.setP6_2_4ID(cursor.getInt(cursor.getColumnIndex("P6_2_4ID")));
				obj.setP6_2_4MOD(cursor.getInt(cursor
						.getColumnIndex("P6_2_4MOD")));
				obj.setP6_2_4TURNO_M(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_M")));
				obj.setP6_2_4TURNO_T(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_T")));
				obj.setP6_2_4TURNO_N(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_N")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public void eliminarAmbiente(P6_2 obj) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete(
				"P6_2_4N",
				"id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_1=? and P6_2_2=?",
				new String[] { obj.getId_local() + "", obj.getNro_Pred() + "",
						obj.getNro_Ed() + "", obj.getP6_2_1() + "",
						obj.getP6_2_2() + "" });
		db.close();
		List<P6_2> ambientes = obtenerListadoAmbientesPorPiso(
				obj.getId_local(), obj.getNro_Ed(), obj.getNro_Pred(),
				obj.getP6_2_2());

		db = util.getWritableDatabase();
		db.delete(
				"P6_2",
				"id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_1=? and P6_2_2=?",
				new String[] { obj.getId_local() + "", obj.getNro_Pred() + "",
						obj.getNro_Ed() + "", obj.getP6_2_1() + "",
						obj.getP6_2_2() + "" });
		db.close();
		List<P6_2_4N> modalidades = obtenerListadoModalidadesPorPiso(
				obj.getId_local(), obj.getNro_Ed(), obj.getNro_Pred(),
				obj.getP6_2_2());

		if (modalidades != null) {
			for (int i = obj.getP6_2_1(); i <= modalidades.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues m = new ContentValues();
				m.put("P6_2_1", i);
				db.update(
						"P6_2_4N",
						m,
						"id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_1=? and P6_2_2=?",
						new String[] { obj.getId_local() + "",
								obj.getNro_Pred() + "", obj.getNro_Ed() + "",
								(i + 1) + "", obj.getP6_2_2() + "" });
				db.close();
			}
		}

		if (ambientes != null) {
			for (int i = obj.getP6_2_1(); i <= ambientes.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues a = new ContentValues();
				a.put("P6_2_1", i);
				db.update(
						"P6_2",
						a,
						"id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_1=? and P6_2_2=?",
						new String[] { obj.getId_local() + "",
								obj.getNro_Pred() + "", obj.getNro_Ed() + "",
								(i + 1) + "", obj.getP6_2_2() + "" });
				db.close();
			}
		}

		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2 where id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_2=?",
						new String[] { obj.getId_local() + "",
								obj.getNro_Pred() + "", obj.getNro_Ed() + "",
								obj.getP6_2_2() + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		db = util.getWritableDatabase();
		ContentValues c = new ContentValues();
		c.put("P5_TotAmb", total);
		db.update("P5_N", c,
				"id_local=? and Nro_Pred=? and P5_NroPiso=? and P5_Ed_Nro=?",
				new String[] { obj.getId_local() + "", obj.getNro_Pred() + "",
						obj.getP6_2_2() + "", obj.getNro_Ed() + "" });
		Cerrar();
	}

	public List<P6_2> obtenerListadoAmbientesPorPiso(String id_local,
			int Nro_Ed, int Nro_Pred, int piso) {
		List<P6_2> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2 where id_local=? and Nro_Ed=? and Nro_Pred=? and P6_2_2=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "", piso + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2>();
			while (!cursor.isAfterLast()) {
				P6_2 obj = new P6_2();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj.setP6_2_3(cursor.getInt(cursor.getColumnIndex("P6_2_3")));
				obj.setP6_2_5(cursor.getInt(cursor.getColumnIndex("P6_2_5")));
				obj.setP6_2_6(cursor.getInt(cursor.getColumnIndex("P6_2_6")));
				obj.setP6_2_7(cursor.getInt(cursor.getColumnIndex("P6_2_7")));
				obj.setP6_2_7_O(cursor.getString(cursor
						.getColumnIndex("P6_2_7_O")));
				obj.setP6_2_8(cursor.getInt(cursor.getColumnIndex("P6_2_8")));
				obj.setP6_2_8_O(cursor.getString(cursor
						.getColumnIndex("P6_2_8_O")));
				obj.setP6_2_9(cursor.getInt(cursor.getColumnIndex("P6_2_9")));
				obj.setP6_2_9_O(cursor.getString(cursor
						.getColumnIndex("P6_2_9_O")));
				obj.setP6_2_10(cursor.getInt(cursor.getColumnIndex("P6_2_10")));
				obj.setP6_2_10_O(cursor.getString(cursor
						.getColumnIndex("P6_2_10_O")));
				obj.setP6_2_11(cursor.getInt(cursor.getColumnIndex("P6_2_11")));
				obj.setP6_2_11_O(cursor.getString(cursor
						.getColumnIndex("P6_2_11_O")));
				obj.setP6_2_12(cursor.getInt(cursor.getColumnIndex("P6_2_12")));
				obj.setP6_2_12_O(cursor.getString(cursor
						.getColumnIndex("P6_2_12_O")));
				obj.setP6_2_13(cursor.getInt(cursor.getColumnIndex("P6_2_13")));
				obj.setP6_2_13_O(cursor.getString(cursor
						.getColumnIndex("P6_2_13_O")));
				obj.setP6_2_14_1(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_1")));
				obj.setP6_2_14_2(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_2")));
				obj.setP6_2_14_3(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_3")));
				obj.setP6_2_14_4(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_4")));
				obj.setP6_2_14_5(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_5")));
				obj.setP6_2_14_6(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_6")));
				obj.setP6_2_14a(cursor.getInt(cursor.getColumnIndex("P6_2_14a")));
				obj.setP6_2_14b_1(cursor.getInt(cursor
						.getColumnIndex("P6_2_14b_1")));
				obj.setP6_2_14b_2(cursor.getInt(cursor
						.getColumnIndex("P6_2_14b_2")));
				obj.setP6_2_15(cursor.getInt(cursor.getColumnIndex("P6_2_15")));
				obj.setP6_2_15_O(cursor.getString(cursor
						.getColumnIndex("P6_2_15_O")));
				obj.setP6_2_15a(cursor.getInt(cursor.getColumnIndex("P6_2_15a")));
				obj.setP6_2_16a(cursor.getInt(cursor.getColumnIndex("P6_2_16a")));
				obj.setP6_2_16a_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_b")));
				obj.setP6_2_16a_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_r")));
				obj.setP6_2_16a_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_m")));
				obj.setP6_2_16b(cursor.getInt(cursor.getColumnIndex("P6_2_16b")));
				obj.setP6_2_16b_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_b")));
				obj.setP6_2_16b_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_r")));
				obj.setP6_2_16b_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_m")));
				obj.setP6_2_16c(cursor.getInt(cursor.getColumnIndex("P6_2_16c")));
				obj.setP6_2_16c_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_b")));
				obj.setP6_2_16c_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_r")));
				obj.setP6_2_16c_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_m")));
				obj.setP6_2_16d(cursor.getInt(cursor.getColumnIndex("P6_2_16d")));
				obj.setP6_2_16d_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_b")));
				obj.setP6_2_16d_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_r")));
				obj.setP6_2_16d_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_m")));
				obj.setP6_2_16e(cursor.getInt(cursor.getColumnIndex("P6_2_16e")));
				obj.setP6_2_16e_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_b")));
				obj.setP6_2_16e_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_r")));
				obj.setP6_2_16e_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_m")));
				obj.setP6_2_16e_O(cursor.getString(cursor
						.getColumnIndex("P6_2_16e_O")));
				obj.setP6_2_16f(cursor.getInt(cursor.getColumnIndex("P6_2_16f")));
				obj.setP6_2_17a(cursor.getInt(cursor.getColumnIndex("P6_2_17a")));
				obj.setP6_2_17b(cursor.getInt(cursor.getColumnIndex("P6_2_17b")));
				obj.setP6_2_17c(cursor.getInt(cursor.getColumnIndex("P6_2_17c")));
				obj.setP6_2_17d(cursor.getInt(cursor.getColumnIndex("P6_2_17d")));
				obj.setP6_2_18a(cursor.getInt(cursor.getColumnIndex("P6_2_18a")));
				obj.setP6_2_18a_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_b")));
				obj.setP6_2_18a_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_r")));
				obj.setP6_2_18a_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_m")));
				obj.setP6_2_18b(cursor.getInt(cursor.getColumnIndex("P6_2_18b")));
				obj.setP6_2_18b_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_b")));
				obj.setP6_2_18b_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_r")));
				obj.setP6_2_18b_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_m")));
				obj.setP6_2_18c(cursor.getInt(cursor.getColumnIndex("P6_2_18c")));
				obj.setP6_2_18c_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_b")));
				obj.setP6_2_18c_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_r")));
				obj.setP6_2_18c_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_m")));
				obj.setP6_2_18d(cursor.getInt(cursor.getColumnIndex("P6_2_18d")));
				obj.setP6_2_18d_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_b")));
				obj.setP6_2_18d_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_r")));
				obj.setP6_2_18d_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_m")));
				obj.setP6_2_18e(cursor.getInt(cursor.getColumnIndex("P6_2_18e")));
				obj.setP6_2_18e_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_b")));
				obj.setP6_2_18e_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_r")));
				obj.setP6_2_18e_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_m")));
				obj.setP6_2_18e_O(cursor.getString(cursor
						.getColumnIndex("P6_2_18e_O")));
				obj.setP6_2_18f(cursor.getInt(cursor.getColumnIndex("P6_2_18f")));
				obj.setP6_2_19a(cursor.getInt(cursor.getColumnIndex("P6_2_19a")));
				obj.setP6_2_19b(cursor.getInt(cursor.getColumnIndex("P6_2_19b")));
				obj.setP6_2_19c(cursor.getInt(cursor.getColumnIndex("P6_2_19c")));
				obj.setP6_2_20OBS(cursor.getString(cursor
						.getColumnIndex("P6_2_20OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_2_4N> obtenerListadoModalidadesPorPiso(String id_local,
			int Nro_Ed, int Nro_Pred, int piso) {
		List<P6_2_4N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2_4N where id_local=? and Nro_Ed=? and Nro_Pred=? and P6_2_2=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "", piso + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2_4N>();
			while (!cursor.isAfterLast()) {
				P6_2_4N obj2_4 = new P6_2_4N();
				obj2_4.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj2_4.setNro_Pred(cursor.getInt(cursor
						.getColumnIndex("Nro_Pred")));
				obj2_4.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj2_4.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj2_4.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj2_4.setP6_2_4ID(cursor.getInt(cursor
						.getColumnIndex("P6_2_4ID")));
				obj2_4.setP6_2_4MOD(cursor.getInt(cursor
						.getColumnIndex("P6_2_4MOD")));
				obj2_4.setP6_2_4TURNO_M(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_M")));
				obj2_4.setP6_2_4TURNO_T(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_T")));
				obj2_4.setP6_2_4TURNO_N(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_N")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj2_4.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj2_4.setSwEnviado(enviado);
				obj2_4.setVersion(cursor.getInt(cursor
						.getColumnIndex("Version")));
				lista.add(obj2_4);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public boolean existenAmbientes(String id_local, int Nro_Pred, int Nro_Ed) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2 where id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_1=?",
						new String[] { id_local + "", Nro_Pred + "",
								Nro_Ed + "", 1 + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public void crearModalidades(List<P6_1_10N> lObj10, int P6_2_1, int P6_2_2) {
		if (lObj10.size() != 0) {
			if (!ExisteModalidad(lObj10.get(0), P6_2_1, P6_2_2)) {
				for (int i = 0; i < lObj10.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("id_local", lObj10.get(i).getId_local());
					c.put("Nro_Pred", lObj10.get(i).getNro_Pred());
					c.put("Nro_Ed", lObj10.get(i).getNro_Ed());
					c.put("P6_2_1", P6_2_1);
					c.put("P6_2_2", P6_2_2);
					c.put("P6_2_4ID", lObj10.get(i).getP6_1_10());
					db.insert("P6_2_4N", null, c);
					db.close();
				}
			}
		}
	}

	public boolean ExisteModalidad(P6_1_10N obj, int P6_2_1, int P6_2_2) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2_4N where id_local=? and Nro_Pred=? and Nro_Ed=? and P6_2_1=? and P6_2_2=?",
						new String[] { obj.getId_local(),
								obj.getNro_Pred() + "", obj.getNro_Ed() + "",
								P6_2_1 + "", P6_2_2 + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public List<Object> obtenerAmbiente(String id_local, int Nro_Ed,
			int Nro_Pred, int P6_2_1, int P6_2_2) {
		P6_2 obj2 = null;
		List<P6_2_4N> lObj2_4 = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2 where id_local=? and Nro_Ed=? and Nro_Pred=? and P6_2_1=? and P6_2_2=? order by P6_2_2 asc",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "", P6_2_1 + "", P6_2_2 + "" });
		if (cursor.moveToFirst()) {
			obj2 = new P6_2();
			obj2.setId_local(id_local);
			obj2.setNro_Ed(Nro_Ed);
			obj2.setP6_2_1(P6_2_1);
			obj2.setP6_2_2(P6_2_2);
			obj2.setNro_Pred(Nro_Pred);
			obj2.setP6_2_3(cursor.getInt(cursor.getColumnIndex("P6_2_3")));
			obj2.setP6_2_5(cursor.getInt(cursor.getColumnIndex("P6_2_5")));
			obj2.setP6_2_6(cursor.getInt(cursor.getColumnIndex("P6_2_6")));
			obj2.setP6_2_7(cursor.getInt(cursor.getColumnIndex("P6_2_7")));
			obj2.setP6_2_7_O(cursor.getString(cursor.getColumnIndex("P6_2_7_O")));
			obj2.setP6_2_8(cursor.getInt(cursor.getColumnIndex("P6_2_8")));
			obj2.setP6_2_8_O(cursor.getString(cursor.getColumnIndex("P6_2_8_O")));
			obj2.setP6_2_9(cursor.getInt(cursor.getColumnIndex("P6_2_9")));
			obj2.setP6_2_9_O(cursor.getString(cursor.getColumnIndex("P6_2_9_O")));
			obj2.setP6_2_10(cursor.getInt(cursor.getColumnIndex("P6_2_10")));
			obj2.setP6_2_10_O(cursor.getString(cursor
					.getColumnIndex("P6_2_10_O")));
			obj2.setP6_2_11(cursor.getInt(cursor.getColumnIndex("P6_2_11")));
			obj2.setP6_2_11_O(cursor.getString(cursor
					.getColumnIndex("P6_2_11_O")));
			obj2.setP6_2_12(cursor.getInt(cursor.getColumnIndex("P6_2_12")));
			obj2.setP6_2_12_O(cursor.getString(cursor
					.getColumnIndex("P6_2_12_O")));
			obj2.setP6_2_13(cursor.getInt(cursor.getColumnIndex("P6_2_13")));
			obj2.setP6_2_13_O(cursor.getString(cursor
					.getColumnIndex("P6_2_13_O")));
			obj2.setP6_2_14_1(cursor.getInt(cursor.getColumnIndex("P6_2_14_1")));
			obj2.setP6_2_14_2(cursor.getInt(cursor.getColumnIndex("P6_2_14_2")));
			obj2.setP6_2_14_3(cursor.getInt(cursor.getColumnIndex("P6_2_14_3")));
			obj2.setP6_2_14_4(cursor.getInt(cursor.getColumnIndex("P6_2_14_4")));
			obj2.setP6_2_14_5(cursor.getInt(cursor.getColumnIndex("P6_2_14_5")));
			obj2.setP6_2_14_6(cursor.getInt(cursor.getColumnIndex("P6_2_14_6")));
			obj2.setP6_2_14a(cursor.getInt(cursor.getColumnIndex("P6_2_14a")));
			obj2.setP6_2_14b_1(cursor.getInt(cursor
					.getColumnIndex("P6_2_14b_1")));
			obj2.setP6_2_14b_2(cursor.getInt(cursor
					.getColumnIndex("P6_2_14b_2")));
			obj2.setP6_2_15(cursor.getInt(cursor.getColumnIndex("P6_2_15")));
			obj2.setP6_2_15_O(cursor.getString(cursor
					.getColumnIndex("P6_2_15_O")));
			obj2.setP6_2_15a(cursor.getInt(cursor.getColumnIndex("P6_2_15a")));
			obj2.setP6_2_16a(cursor.getInt(cursor.getColumnIndex("P6_2_16a")));
			obj2.setP6_2_16a_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_16a_b")));
			obj2.setP6_2_16a_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_16a_r")));
			obj2.setP6_2_16a_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_16a_m")));
			obj2.setP6_2_16b(cursor.getInt(cursor.getColumnIndex("P6_2_16b")));
			obj2.setP6_2_16b_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_16b_b")));
			obj2.setP6_2_16b_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_16b_r")));
			obj2.setP6_2_16b_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_16b_m")));
			obj2.setP6_2_16c(cursor.getInt(cursor.getColumnIndex("P6_2_16c")));
			obj2.setP6_2_16c_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_16c_b")));
			obj2.setP6_2_16c_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_16c_r")));
			obj2.setP6_2_16c_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_16c_m")));
			obj2.setP6_2_16d(cursor.getInt(cursor.getColumnIndex("P6_2_16d")));
			obj2.setP6_2_16d_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_16d_b")));
			obj2.setP6_2_16d_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_16d_r")));
			obj2.setP6_2_16d_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_16d_m")));
			obj2.setP6_2_16e(cursor.getInt(cursor.getColumnIndex("P6_2_16e")));
			obj2.setP6_2_16e_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_16e_b")));
			obj2.setP6_2_16e_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_16e_r")));
			obj2.setP6_2_16e_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_16e_m")));
			obj2.setP6_2_16e_O(cursor.getString(cursor
					.getColumnIndex("P6_2_16e_O")));
			obj2.setP6_2_16f(cursor.getInt(cursor.getColumnIndex("P6_2_16f")));
			obj2.setP6_2_17a(cursor.getInt(cursor.getColumnIndex("P6_2_17a")));
			obj2.setP6_2_17b(cursor.getInt(cursor.getColumnIndex("P6_2_17b")));
			obj2.setP6_2_17c(cursor.getInt(cursor.getColumnIndex("P6_2_17c")));
			obj2.setP6_2_17d(cursor.getInt(cursor.getColumnIndex("P6_2_17d")));
			obj2.setP6_2_18a(cursor.getInt(cursor.getColumnIndex("P6_2_18a")));
			obj2.setP6_2_18a_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_18a_b")));
			obj2.setP6_2_18a_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_18a_r")));
			obj2.setP6_2_18a_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_18a_m")));
			obj2.setP6_2_18b(cursor.getInt(cursor.getColumnIndex("P6_2_18b")));
			obj2.setP6_2_18b_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_18b_b")));
			obj2.setP6_2_18b_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_18b_r")));
			obj2.setP6_2_18b_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_18b_m")));
			obj2.setP6_2_18c(cursor.getInt(cursor.getColumnIndex("P6_2_18c")));
			obj2.setP6_2_18c_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_18c_b")));
			obj2.setP6_2_18c_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_18c_r")));
			obj2.setP6_2_18c_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_18c_m")));
			obj2.setP6_2_18d(cursor.getInt(cursor.getColumnIndex("P6_2_18d")));
			obj2.setP6_2_18d_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_18d_b")));
			obj2.setP6_2_18d_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_18d_r")));
			obj2.setP6_2_18d_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_18d_m")));
			obj2.setP6_2_18e(cursor.getInt(cursor.getColumnIndex("P6_2_18e")));
			obj2.setP6_2_18e_b(cursor.getInt(cursor
					.getColumnIndex("P6_2_18e_b")));
			obj2.setP6_2_18e_r(cursor.getInt(cursor
					.getColumnIndex("P6_2_18e_r")));
			obj2.setP6_2_18e_m(cursor.getInt(cursor
					.getColumnIndex("P6_2_18e_m")));
			obj2.setP6_2_18e_O(cursor.getString(cursor
					.getColumnIndex("P6_2_18e_O")));
			obj2.setP6_2_18f(cursor.getInt(cursor.getColumnIndex("P6_2_18f")));
			obj2.setP6_2_19a(cursor.getInt(cursor.getColumnIndex("P6_2_19a")));
			obj2.setP6_2_19b(cursor.getInt(cursor.getColumnIndex("P6_2_19b")));
			obj2.setP6_2_19c(cursor.getInt(cursor.getColumnIndex("P6_2_19c")));
			obj2.setP6_2_20OBS(cursor.getString(cursor
					.getColumnIndex("P6_2_20OBS")));
			boolean estado = cursor.getInt(cursor.getColumnIndex("SwCompleto")) == 1 ? true
					: false;
			obj2.setSwCompleto(estado);
			boolean enviado = cursor.getInt(cursor.getColumnIndex("SwEnviado")) == 1 ? true
					: false;
			obj2.setSwEnviado(enviado);
			obj2.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));

		}

		Cursor c = db
				.rawQuery(
						"select * from P6_2_4N where id_local=? and Nro_Ed=? and Nro_Pred=? and P6_2_1=? and P6_2_2=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "", P6_2_1 + "", P6_2_2 + "" });

		lObj2_4 = new ArrayList<P6_2_4N>();
		if (c.moveToFirst()) {
			while (!c.isAfterLast()) {
				P6_2_4N obj2_4 = new P6_2_4N();
				obj2_4.setId_local(id_local);
				obj2_4.setNro_Ed(Nro_Ed);
				obj2_4.setP6_2_1(P6_2_1);
				obj2_4.setP6_2_2(P6_2_2);
				obj2_4.setNro_Pred(Nro_Pred);
				obj2_4.setP6_2_4ID(c.getInt(c.getColumnIndex("P6_2_4ID")));
				obj2_4.setP6_2_4MOD(c.getInt(c.getColumnIndex("P6_2_4MOD")));
				obj2_4.setP6_2_4TURNO_M(c.getInt(c
						.getColumnIndex("P6_2_4TURNO_M")));
				obj2_4.setP6_2_4TURNO_T(c.getInt(c
						.getColumnIndex("P6_2_4TURNO_T")));
				obj2_4.setP6_2_4TURNO_N(c.getInt(c
						.getColumnIndex("P6_2_4TURNO_N")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj2_4.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj2_4.setSwEnviado(enviado);
				obj2_4.setVersion(cursor.getInt(cursor
						.getColumnIndex("Version")));
				lObj2_4.add(obj2_4);
				c.moveToNext();
			}
		}
		List<Object> lista = new ArrayList<Object>();
		lista.add(obj2);
		lista.add(lObj2_4);
		Cerrar();
		return lista;
	}

	public boolean ExisteAmbiente(P6_2 obj) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_2 where id_local=? and Nro_Ed=? and P6_2_1=? and Nro_Pred=?",
						new String[] { obj.getId_local() + "",
								obj.getNro_Ed() + "", obj.getP6_2_1() + "",
								obj.getNro_Pred() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public void actualizarModalidades(List<P6_2_4N> obj2) {
		if (obj2 != null) {
			for (int i = 0; i < obj2.size(); i++) {
				db = util.getWritableDatabase();
				P6_2_4N o = obj2.get(i);
				ContentValues c = new ContentValues();
				c.put("P6_2_4MOD", o.getP6_2_4MOD());
				c.put("P6_2_4TURNO_M", o.getP6_2_4TURNO_M());
				c.put("P6_2_4TURNO_T", o.getP6_2_4TURNO_T());
				c.put("P6_2_4TURNO_N", o.getP6_2_4TURNO_N());
				c.put("Version", o.getVersion());
				c.put("SwCompleto", o.isSwCompleto());
				c.put("SwEnviado", o.isSwEnviado());
				db.update(
						"P6_2_4N",
						c,
						"id_local=? and Nro_Ed=? and Nro_Pred=? and P6_2_1=? and P6_2_2=? and P6_2_4ID=?",
						new String[] { o.getId_local(), o.getNro_Ed() + "",
								o.getNro_Pred() + "", o.getP6_2_1() + "",
								o.getP6_2_2() + "", o.getP6_2_4ID() + "" });
				db.close();
			}
		}
	}

	public void actualizarSeccionB(P6_2 obj, List<P6_2_4N> lObj2) {
		ContentValues valores = new ContentValues();
		valores.put("P6_2_3", obj.getP6_2_3());
		valores.put("P6_2_5", obj.getP6_2_5());
		valores.put("P6_2_6", obj.getP6_2_6());
		valores.put("P6_2_7", obj.getP6_2_7());
		valores.put("P6_2_7_O", obj.getP6_2_7_O());
		valores.put("P6_2_8", obj.getP6_2_8());
		valores.put("P6_2_8_O", obj.getP6_2_8_O());
		valores.put("P6_2_9", obj.getP6_2_9());
		valores.put("P6_2_9_O", obj.getP6_2_9_O());
		valores.put("P6_2_10", obj.getP6_2_10());
		valores.put("P6_2_10_O", obj.getP6_2_10_O());
		valores.put("P6_2_11",
				(obj.getP6_2_11() == 0 ? null : obj.getP6_2_11()));
		valores.put("P6_2_11_O", obj.getP6_2_11_O());
		valores.put("P6_2_12",
				(obj.getP6_2_12() == 0 ? null : obj.getP6_2_12()));
		valores.put("P6_2_12_O", obj.getP6_2_12_O());
		valores.put("P6_2_13",
				(obj.getP6_2_13() == 0 ? null : obj.getP6_2_13()));
		valores.put("P6_2_13_O", obj.getP6_2_13_O());
		valores.put("P6_2_14_1", obj.getP6_2_14_1());
		valores.put("P6_2_14_2", obj.getP6_2_14_2());
		valores.put("P6_2_14_3", obj.getP6_2_14_3());
		valores.put("P6_2_14_4", obj.getP6_2_14_4());
		valores.put("P6_2_14_5", obj.getP6_2_14_5());
		valores.put("P6_2_14_6", obj.getP6_2_14_6());
		valores.put("P6_2_14a", obj.getP6_2_14a());
		valores.put("P6_2_14b_1", obj.getP6_2_14b_1());
		valores.put("P6_2_14b_2", obj.getP6_2_14b_2());
		valores.put("P6_2_15", obj.getP6_2_15());
		valores.put("P6_2_15_O", obj.getP6_2_15_O());
		valores.put("P6_2_15a", obj.getP6_2_15a());
		valores.put("P6_2_16a", obj.getP6_2_16a());
		valores.put("P6_2_16a_b", obj.getP6_2_16a_b());
		valores.put("P6_2_16a_r", obj.getP6_2_16a_r());
		valores.put("P6_2_16a_m", obj.getP6_2_16a_m());
		valores.put("P6_2_16b", obj.getP6_2_16b());
		valores.put("P6_2_16b_b", obj.getP6_2_16b_b());
		valores.put("P6_2_16b_r", obj.getP6_2_16b_r());
		valores.put("P6_2_16b_m", obj.getP6_2_16b_m());
		valores.put("P6_2_16c", obj.getP6_2_16c());
		valores.put("P6_2_16c_b", obj.getP6_2_16c_b());
		valores.put("P6_2_16c_r", obj.getP6_2_16c_r());
		valores.put("P6_2_16c_m", obj.getP6_2_16c_m());
		valores.put("P6_2_16d", obj.getP6_2_16d());
		valores.put("P6_2_16d_b", obj.getP6_2_16d_b());
		valores.put("P6_2_16d_r", obj.getP6_2_16d_r());
		valores.put("P6_2_16d_m", obj.getP6_2_16d_m());
		valores.put("P6_2_16e", obj.getP6_2_16e());
		valores.put("P6_2_16e_b", obj.getP6_2_16e_b());
		valores.put("P6_2_16e_r", obj.getP6_2_16e_r());
		valores.put("P6_2_16e_m", obj.getP6_2_16e_m());
		valores.put("P6_2_16e_O", obj.getP6_2_16e_O());
		valores.put("P6_2_16f", obj.getP6_2_16f());
		valores.put("P6_2_17a", obj.getP6_2_17a());
		valores.put("P6_2_17b", obj.getP6_2_17b());
		valores.put("P6_2_17c", obj.getP6_2_17c());
		valores.put("P6_2_17d", obj.getP6_2_17d());
		valores.put("P6_2_18a", obj.getP6_2_18a());
		valores.put("P6_2_18a_b", obj.getP6_2_18a_b());
		valores.put("P6_2_18a_r", obj.getP6_2_18a_r());
		valores.put("P6_2_18a_m", obj.getP6_2_18a_m());
		valores.put("P6_2_18b", obj.getP6_2_18b());
		valores.put("P6_2_18b_b", obj.getP6_2_18b_b());
		valores.put("P6_2_18b_r", obj.getP6_2_18b_r());
		valores.put("P6_2_18b_m", obj.getP6_2_18b_m());
		valores.put("P6_2_18c", obj.getP6_2_18c());
		valores.put("P6_2_18c_b", obj.getP6_2_18c_b());
		valores.put("P6_2_18c_r", obj.getP6_2_18c_r());
		valores.put("P6_2_18c_m", obj.getP6_2_18c_m());
		valores.put("P6_2_18d", obj.getP6_2_18d());
		valores.put("P6_2_18d_b", obj.getP6_2_18d_b());
		valores.put("P6_2_18d_r", obj.getP6_2_18d_r());
		valores.put("P6_2_18d_m", obj.getP6_2_18d_m());
		valores.put("P6_2_18e", obj.getP6_2_18e());
		valores.put("P6_2_18e_b", obj.getP6_2_18e_b());
		valores.put("P6_2_18e_r", obj.getP6_2_18e_r());
		valores.put("P6_2_18e_m", obj.getP6_2_18e_m());
		valores.put("P6_2_18e_O", obj.getP6_2_18e_O());
		valores.put("P6_2_18f", obj.getP6_2_18f());
		valores.put("P6_2_19a", obj.getP6_2_19a());
		valores.put("P6_2_19b", obj.getP6_2_19b());
		valores.put("P6_2_19c", obj.getP6_2_19c());
		valores.put("P6_2_20OBS", obj.getP6_2_20OBS());
		valores.put("Version", obj.getVersion());
		valores.put("SwCompleto", obj.isSwCompleto());
		valores.put("SwEnviado", obj.isSwEnviado());

		db = util.getWritableDatabase();
		db.update(
				"P6_2",
				valores,
				"id_local=? and Nro_Ed=? and P6_2_1=? and Nro_Pred=? and P6_2_2=?",
				new String[] { obj.getId_local() + "", obj.getNro_Ed() + "",
						obj.getP6_2_1() + "", obj.getNro_Pred() + "",
						obj.getP6_2_2() + "" });
		if (lObj2.size() != 0) {
			for (int i = 0; i < lObj2.size(); i++) {
				valores.clear();
				P6_2_4N o = lObj2.get(i);
				valores.put("P6_2_4MOD", o.getP6_2_4MOD());
				valores.put("P6_2_4TURNO_M", o.getP6_2_4TURNO_M());
				valores.put("P6_2_4TURNO_T", o.getP6_2_4TURNO_T());
				valores.put("P6_2_4TURNO_N", o.getP6_2_4TURNO_N());
				valores.put("Version", o.getVersion());
				valores.put("SwCompleto", o.isSwCompleto());
				valores.put("SwEnviado", o.isSwEnviado());
				db.update(
						"P6_2_4N",
						valores,
						"id_local=? and Nro_Ed=? and Nro_Pred=? and P6_2_1=? and P6_2_2=? and P6_2_4ID=?",
						new String[] { o.getId_local(), o.getNro_Ed() + "",
								o.getNro_Pred() + "", o.getP6_2_1() + "",
								o.getP6_2_2() + "", o.getP6_2_4ID() + "" });
			}
		}
		db.close();
	}

	protected void Cerrar() {
		cursor.close();
		db.close();
	}

	public boolean EdificacionCompleta(String id_local, int Nro_Ed, int Nro_Pred) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P6_1 where id_local=? and Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local, Nro_Ed + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			if (cursor.getInt(cursor.getColumnIndex("SwCompleto")) == 0) {
				Cerrar();
				return false;
			}
		} else {
			Cerrar();
			return false;
		}

		cursor = null;
		cursor = db
				.rawQuery(
						"select * from P6_2  where id_local=? and Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local, Nro_Ed + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				if (cursor.getInt(cursor.getColumnIndex("SwCompleto")) == 0) {
					Cerrar();
					return false;
				}
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return false;
		}
		Cerrar();
		return true;
	}
}
